VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmGLD160 
   BackColor       =   &H8000000D&
   Caption         =   "GLD160"
   ClientHeight    =   3495
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7335
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   3495
   ScaleWidth      =   7335
   StartUpPosition =   3  'Windows Default
   Begin MSDataListLib.DataCombo cboCICCD 
      Bindings        =   "frmGLD160.frx":0000
      Height          =   315
      Left            =   2235
      TabIndex        =   18
      Top             =   1125
      Visible         =   0   'False
      Width           =   1545
      _ExtentX        =   2725
      _ExtentY        =   556
      _Version        =   393216
      ListField       =   "CMDSC"
      BoundColumn     =   "CMCCD"
      Text            =   ""
   End
   Begin VB.TextBox txtCICCD 
      Alignment       =   2  'Center
      Height          =   288
      Left            =   2235
      TabIndex        =   16
      Top             =   1125
      Width           =   1215
   End
   Begin VB.TextBox txtCMDSC 
      Height          =   345
      Left            =   2220
      MultiLine       =   -1  'True
      TabIndex        =   15
      Top             =   1470
      Width           =   2625
   End
   Begin MSAdodcLib.Adodc Adodc2 
      Height          =   345
      Left            =   5550
      Top             =   30
      Visible         =   0   'False
      Width           =   1755
      _ExtentX        =   3096
      _ExtentY        =   609
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "2.CCI"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   3585
      Top             =   45
      Visible         =   0   'False
      Width           =   1920
      _ExtentX        =   3387
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "1.CCM"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00E0E0E0&
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   870
      Left            =   435
      TabIndex        =   7
      Top             =   1935
      Width           =   4455
      Begin VB.TextBox txtCIDTE 
         Height          =   288
         Left            =   1785
         TabIndex        =   11
         Top             =   495
         Width           =   1215
      End
      Begin VB.TextBox txtCICCR 
         Height          =   315
         Left            =   1785
         TabIndex        =   9
         Top             =   120
         Width           =   1215
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Date"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   225
         Index           =   3
         Left            =   1110
         TabIndex        =   12
         Top             =   510
         Width           =   510
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Currency rate"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   225
         Index           =   2
         Left            =   435
         TabIndex        =   10
         Top             =   120
         Width           =   1245
      End
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "&Delete"
      Height          =   372
      Left            =   4740
      TabIndex        =   6
      Top             =   2985
      Width           =   960
   End
   Begin VB.CommandButton cmdAddnew 
      Caption         =   "&New"
      Height          =   372
      Left            =   480
      TabIndex        =   4
      Top             =   2985
      Width           =   996
   End
   Begin VB.CommandButton cmdEdit 
      Caption         =   "&Edit"
      Height          =   372
      Left            =   1530
      TabIndex        =   3
      Top             =   2985
      Width           =   948
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save"
      Height          =   372
      Left            =   2535
      TabIndex        =   2
      Top             =   2985
      Width           =   984
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   372
      Left            =   3600
      TabIndex        =   1
      Top             =   2985
      Width           =   1032
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "&Exit"
      Height          =   372
      Left            =   5790
      TabIndex        =   0
      Top             =   2985
      Width           =   1080
   End
   Begin MSDataListLib.DataList lstCIDTE 
      Bindings        =   "frmGLD160.frx":0015
      Height          =   1620
      Left            =   5145
      TabIndex        =   13
      Top             =   1020
      Width           =   1695
      _ExtentX        =   2990
      _ExtentY        =   2858
      _Version        =   393216
      ForeColor       =   16512
      ListField       =   "CIDTE"
      BoundColumn     =   "CICCD"
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Currency code"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   7.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FFFF&
      Height          =   225
      Index           =   5
      Left            =   765
      TabIndex        =   17
      Top             =   1140
      Width           =   1365
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Date"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   -1  'True
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FFFF&
      Height          =   225
      Index           =   4
      Left            =   4440
      TabIndex        =   14
      Top             =   1005
      Width           =   510
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "GLD160"
      BeginProperty Font 
         Name            =   "VNI-Present"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   -1  'True
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   510
      Index           =   0
      Left            =   60
      TabIndex        =   8
      Top             =   0
      Width           =   1680
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Rate Exchange Maintenance"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   16.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   495
      Index           =   1
      Left            =   1155
      TabIndex        =   5
      Top             =   510
      Width           =   5415
   End
End
Attribute VB_Name = "frmGLD160"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim OldCICCD As String
Private Sub WriteToFile()
Dim SQLInsert As String
Dim RecCCI As Recordset
If Not IsDate(txtCIDTE) Then
    MsgBox "Invalid Date!"
    Exit Sub
End If
If Not IsNumeric(txtCICCR) Or Val(txtCICCR) <= 0 Then
    MsgBox "Invalid Rate!"
    Exit Sub
End If
txtCIDTE = Format(txtCIDTE, "yyyy-mm-dd hh:mm:ss")
Set RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtCICCD & "'" & _
    " and day(CIDTE)=" & Day(txtCIDTE) & " and month(CIDTE)=" & Month(txtCIDTE) & _
    " and year(CIDTE)=" & Year(txtCIDTE))
If RecCCI.EOF Then
    SQLInsert = " INSERT INTO CCI " & _
                  "(CICCD,CIDTE,CICCR) " & _
                "VALUES " & _
                  "('" & txtCICCD & "', '" & txtCIDTE & "'," & txtCICCR & ")"
Else
    SQLInsert = "UPDATE CCM SET CICCD = '" & txtCICCD & "', CIDTE ='" & txtCIDTE & "' " & _
                ",CICCR=" & txtCICCR & " WHERE CICCD ='" & OldCICCD & "'"
             
End If

DBconn.Execute SQLInsert
RecCCI.Close
End Sub

Private Sub WriteToScreen()
If ISADDING Then 'gan rong
        txtCICCD = ""
        txtCMDSC = ""
        txtCICCR = 0
        txtCIDTE = Date
       ' txtUMCVF = 0
Else
        Dim TBL As ADODB.Recordset
        Set TBL = New ADODB.Recordset
        TBL.Open "  Select CCM.*From CCM where  CMCCD ='" & cboCMCCD.BoundText & "'", DBconn, adOpenKeyset, adLockOptimistic, adCmdText
        If TBL.EOF = False Then
            txtCICCD = IIf(IsNull(TBL!CMCCD), "", TBL!CMCCD)
            txtCMDSC = txtCMDSC = Find("CCM", "CMDSC", " WHERE CMCCD='" & txtCICCD & "'")
            txtCICCR = IIf(IsNull(TBL!CICCR), "", TBL!CICCR)
            txtCIDTE = IIf(IsNull(TBL!CIDTE), "", TBL!CIDTE)
        '    txtUMCVF = IIf(IsNull(TBL!UMCVF), "", TBL!UMCVF)
        Else
            cboCICCD.BoundText = ""
            txtCICCD = ""
            txtCMDSC = ""
            txtCIDTE = Date
        End If
        TBL.Close
End If
OldCICCD = txtCICCD
End Sub

Sub ButtonStatus()
cmdAddnew.Enabled = Not ISEDITING
cmdEdit.Enabled = Not ISEDITING
cmdSave.Enabled = ISEDITING ' And txtIMITN <> ""
cmdDelete.Enabled = Not ISEDITING 'And txtIMITN <> ""
cmdCancel.Enabled = ISEDITING
Frame1.Enabled = ISEDITING
'txtIMITN.Locked = Not ISADDING ' Lock item code tru truong hop ISADDING=true
'txtDepartment.Enabled = ISEDITING
'cboDepartment.Visible = Not ISADDING
'txtDepartmentID.Visible = ISADDING
End Sub

Private Sub cboCMCCD_Click(Area As Integer)
If Area = 2 Then
    WriteToScreen
End If


End Sub

Private Sub cboCICCD_Click(Area As Integer)
If Area = 2 Then
    txtCICCD = cboCICCD.BoundText
    Adodc2.RecordSource = "Select * from CCI where CICCD='" & txtCICCD & "' order by CIDTE DESC"  'Currency rate
    Adodc2.Refresh
    txtCMDSC = cboCICCD.Text
    cboCICCD.Visible = False
    If Not ISADDING Then
        Dim RecCCI As Recordset
        Set RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtCICCD & "' order by CIDTE DESC")
        If Not RecCCI.EOF Then
            txtCICCR = RecCCI!CICCR
            txtCIDTE = RecCCI!CIDTE
        Else
            txtCICCR = 0
        End If
    End If
End If
End Sub

Private Sub cmdAddnew_Click()
ISADDING = True
ISEDITING = True
WriteToScreen

' Ham Gan tri man hinh
ButtonStatus

End Sub

Private Sub cmdCancel_Click()
' Gan tri man nhinh
ISADDING = False
ISEDITING = False

ButtonStatus
txtCICCD = cboCICCD.BoundText
WriteToScreen


End Sub

Private Sub cmdDelete_Click()
Dim SQL As String
SQL = "DELETE FROM CCM WHERE CMCCD = '" & cboCMCCD.BoundText & "'"

Set cmdExecute = New ADODB.Command
Set cmdExecute.ActiveConnection = DBconn
cmdExecute.CommandText = SQL
cmdExecute.Execute
Adodc1.Refresh
'WriteToScreen (0)

End Sub

Private Sub cmdEdit_Click()
ISEDITING = True
' Ham gan tri man hinh
ISADDING = False
ISEDITING = True


ButtonStatus

End Sub

Private Sub cmdExit_Click()
Unload frmGLD160
End Sub

Private Sub cmdSave_Click()


WriteToFile
Adodc1.Refresh

'''''''''''
ISADDING = False
ISEDITING = False

ButtonStatus


End Sub

Private Sub Form_Load()

Adodc1.ConnectionString = ConnectString
Adodc1.ConnectionTimeout = 10
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "CCM" 'Currency code
Adodc1.Refresh

Adodc2.ConnectionString = ConnectString
Adodc2.ConnectionTimeout = 10
Adodc2.CommandType = adCmdText
Adodc2.RecordSource = "Select * from CCI" 'Currency rate
Adodc2.Refresh
ISADDING = False
ISEDITING = False
ButtonStatus

End Sub

Private Sub lstCIDTE_Click()
    txtCICCD = lstCIDTE.BoundText
    txtCIDTE = lstCIDTE
    txtCMDSC = Find("CCM", "CMDSC", " WHERE CMCCD='" & txtCICCD & "'")
    cboCICCD.Visible = False
    Dim RecCCI As Recordset
    Set RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtCICCD & "'" & _
        " and day(CIDTE)=" & Day(txtCIDTE) & " and month(CIDTE)=" & Month(txtCIDTE) & _
        " and year(CIDTE)=" & Year(txtCIDTE))
    If Not RecCCI.EOF Then
        txtCICCR = RecCCI!CICCR
    Else
        txtCICCR = 0
    End If
End Sub

Private Sub txtCICCD_KeyPress(KeyAscii As Integer)
Dim Result As String
If KeyAscii = 13 Then
    Result = Find("CCM", "CMDSC", " WHERE CMCCD='" & txtCICCD & "'")
    Adodc2.RecordSource = "Select * from CCI where CICCD='" & txtCICCD & "' order by CIDTE DESC"  'Currency rate
    Adodc2.Refresh
    If Result <> "" Then
        txtCMDSC = Result
        Dim RecCCI As Recordset
        Set RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtCICCD & "' order by CIDTE DESC")
        If Not RecCCI.EOF Then
            txtCICCR = RecCCI!CICCR
            txtCIDTE = RecCCI!CIDTE
        Else
            txtCICCR = 0
            txtCIDTE = ""
        End If
    Else
        cboCICCD.Visible = True
        cboCICCD.SetFocus
    End If
End If
End Sub
